//
//  CinemaViewController.m
//  UI_APP_Project_Bean
//
//  Created by dllo on 16/6/23.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CinemaViewController.h"
#import "CinemalistModel.h"
#import "ThreeLabelTableViewCell.h"
#import "CinemaDetailViewController.h"


@interface CinemaViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, retain)NSMutableArray *cinemaListArray;
@end

@implementation CinemaViewController

- (void)dealloc
{
    [_cinemaListArray release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    [self config];
    [self handleData];
    [self creatTableView];
    
}

-(void)config{

    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.37 green:0.6 blue:0.7 alpha:1];
    self.navigationItem.title = @"影院";
    
//    self.navigationItem.titleView =ww;
    self.cinemaListArray = [NSMutableArray array];
    
}

-(void)handleData{
    
    NSString *path = [[NSBundle mainBundle]pathForResource:@"cinemalist" ofType:@".txt"];
    
    NSData *data = [NSData dataWithContentsOfFile:path];
    
    NSError *error = nil;
    
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
    
    NSDictionary *cinDic= [dic objectForKey:@"result"];
    NSArray *cinemaArray = [cinDic objectForKey:@"data"];
    for (NSDictionary *dic in cinemaArray) {
        CinemalistModel *model = [[CinemalistModel alloc]init];
        
        [model setValuesForKeysWithDictionary:dic];
        
        [self.cinemaListArray addObject:model];
        
        
    }
    NSLog(@"cina****%@", self.cinemaListArray);
    
}


-(void)creatTableView{
    UITableView *tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    
    [self.view addSubview:tableView];
    [tableView release];
    
    tableView.delegate = self;
    tableView.dataSource = self;
    
    tableView.rowHeight = 170;
    
    
    [tableView registerClass:[ThreeLabelTableViewCell class] forCellReuseIdentifier:@"threeLabelCell"];
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.cinemaListArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    ThreeLabelTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"threeLabelCell"];
    
    cell.cinemaModel = [self.cinemaListArray objectAtIndex:indexPath.row];
    
    
    return cell;
    
    
}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    CinemaDetailViewController *cinemaVC = [[CinemaDetailViewController alloc]init];
    
    cinemaVC.cinemaMode = [self.cinemaListArray objectAtIndex:indexPath.row];
    
    
    [self.navigationController pushViewController:cinemaVC animated:YES];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
